package com.emeraldparser.symbol;

import com.emeraldparser.util.HashCodes;
import com.google.common.base.Objects;
import com.google.common.base.Preconditions;

/**
 * 
 * @author Adam Paynter
 *
 */
public final class NamedSymbolClass extends AtomicSymbolClass {

	private final String name;
	private final transient int hashCode;

	public NamedSymbolClass(String name) {
		this.name = Preconditions.checkNotNull(name, "Name must not be null");
		this.hashCode = HashCodes.classSpecificHashCode(NamedSymbolClass.class, name);
	}

	public String getName() {
		return name;
	}

	@Override
	public String toString() {
		return name;
	}

	@Override
	public int hashCode() {
		return hashCode;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		
		if (obj == null) {
			return false;
		}
		
		if (getClass() != obj.getClass()) {
			return false;
		}
		
		NamedSymbolClass other = (NamedSymbolClass) obj;
		
		return Objects.equal(name, other.name);
	}

	@Override
	public <I, O> O accept(SymbolClassVisitor<I, O> visitor, I input) {
		return visitor.visitNamedSymbolClass(this, input);
	}

}
